package com.aoxin.controller.opm;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aoxin.model.dto.RoleEmployeeDto;
import com.aoxin.service.inter.opm.RoleEmployeeService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;
import com.aoxin.util.enumerate.OperateType;
import com.aoxin.util.log.LogInfo;

/**
 * 角色Controller
 * 
 * @author Melody
 * @date 2018年3月21日 上午11:09:33
 */
@Controller
@ResponseBody
@RequestMapping("/web/roleEmployee")
public class RoleEmployeeController {
	
	@Autowired
	private RoleEmployeeService roleEmployeeService;

	/**
	 * 批量添加角色人员
	 * 
	 * @param roleId
	 *            角色ID
	 * @param menuIds
	 *            人员ID集合
	 */
	@RequestMapping("insertRoleEmployeeList")
	@LogInfo(content = "角色人员",operateType = OperateType.INSERT)
	public AjaxRes insertRoleEmployeeList(@RequestParam("roleId") Integer roleId, @RequestParam("employeeIds") List<Integer> employeeIds, AjaxRes ajaxRes) {
		try {
			this.roleEmployeeService.insertSlfRoleEmployeeList(roleId, employeeIds);
			ajaxRes.setSucceedMsg(Const.SAVE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 删除角色人员
	 * 
	 * @param roleEmployeeIds
	 *            角色人员集合
	 * @param ajaxRes
	 */
	@RequestMapping("deleteRoleEmployees")
	@LogInfo(content = "角色人员",operateType = OperateType.DELETE)
	public AjaxRes deleteRoleEmployees(@RequestParam("roleEmployeeIds") List<Integer> roleEmployeeIds, AjaxRes ajaxRes) {
		try {
			this.roleEmployeeService.deleteSlfRoleEmployeeByIds(roleEmployeeIds);
			ajaxRes.setSucceedMsg(Const.DEL_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 根据角色ID查询人员
	 * 
	 * @param roleId
	 *            角色ID
	 * @return 人员
	 */
	@RequestMapping("getEmployeeListByRole")
	@LogInfo(content = "角色人员",operateType = OperateType.QUERY)
	public AjaxRes getEmployeeListByRole( @RequestParam Map<String,Object> map, AjaxRes ajaxRes) {
		try {
			List<RoleEmployeeDto> data = this.roleEmployeeService.getEmployeeListByRoleId(map);
			ajaxRes.setSucceed(data, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
}
